<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="日期">
        <el-date-picker
          v-model="queryParams.checkDate"
          size="small"
          style="width: 140px"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['smartdor:sdhygiene:remove']"
        >删除</el-button>
      </el-col>

    </el-row>

    <el-table v-loading="loading" :data="sdattenceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="设备出入类型" align="center" prop="deviceNo" :show-overflow-tooltip="true" :formatter="devicestatusFormat" />
      <el-table-column label="学号" align="center" prop="studentNo"  />
      <el-table-column label="班级" align="center" prop="className"  />
      <el-table-column label="学生姓名" align="center" prop="studentName"  />
      <el-table-column label="宿舍信息" align="center" prop="dorAddress"  />
      <el-table-column label="考勤时间" align="center" prop="accessDate"  width="160" />
      <el-table-column label="考勤状态" align="center" prop="attenceStatus" :show-overflow-tooltip="true" :formatter="attencestatusFormat" />
      <!-- <el-table-column label="缺勤处理状态" align="center" prop="absenceProcessStatus" :show-overflow-tooltip="true"  :formatter="absenceProcessStatusFormat"/> -->
      <el-table-column label="创建时间" align="center" prop="createTimef" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100" >
        <template slot-scope="scope">
          <el-button v-if="scope.row.attenceStatus==='4'"
                  size="mini"
                  circle type="info"
                  icon="el-icon-view"
                  @click="handleView4(scope.row,scope.index)"
                  v-hasPermi="['smartdor:sdattence:query']"
          />
          <el-button v-if="scope.row.attenceStatus==='2' || scope.row.attenceStatus==='3'"
                  size="mini"
                  circle type="info"
                  icon="el-icon-view"
                  @click="handleView5(scope.row,scope.index)"
                  v-hasPermi="['smartdor:sdattence:query']"
          />
          <el-button
            size="mini"
            circle type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['smartdor:sdhygiene:remove']"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 请假详细 -->
    <el-dialog title="请假详细" :visible.sync="open4" width="700px">
      <el-form ref="form" :model="form" label-width="140px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学号："> {{ form.studentNo }} </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级："> {{ form.className }} </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生姓名："> {{ form.studentName }} </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生手机号："> {{ form.studentPhone }} </el-form-item>
          </el-col>
         <el-col :span="12">
            <el-form-item label="请假类型：">{{ leaveTypeFormat(form) }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请假日期："> {{ form.leaveDate }} </el-form-item>
          </el-col>
         <el-col :span="12">
            <el-form-item label="状态：">{{ leaveStatusFormat(form) }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="请假原因：">{{form.leaveReason}}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="家长描述信息：">{{form.parentDesc}}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="班主任描述信息：">{{form.teacherDesc}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请假记录提交时间:"> {{form.createTime}}</el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open4 = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 考勤异常详细(晚归/缺勤) -->
    <el-dialog title="考勤异常详细" :visible.sync="open5" width="700px">
      <el-form ref="form1" :model="form1" label-width="140px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学号："> {{ form1.studentNo }} </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级："> {{ form1.className }} </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生姓名："> {{ form1.studentName }} </el-form-item>
          </el-col>
          <el-col :span="12">
             <el-form-item label="处理状态：">{{ processStatusFormat(form1) }}</el-form-item>
           </el-col>
         <el-col :span="12">
            <el-form-item label="处理描述：">{{ form1.processDesc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理人："> {{ form1.processPerson }} </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="处理时间：">{{form1.createTime}}</el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open5 = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listsdattence,delSdattence,queryleave,queryexception} from "@/api/smartdor/sdattence.js";
  import {  getBStudentByNo} from "@/api/basedata/bstudent";
  export default {
    name: "sdattence",
    data() {
      return {
        studentName:'',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 字典表格数据
        sdattenceList: [],
        // 请假类型
        leaveTypeOptions: [],
        // 请假状态数据字典
        leaveStatusOptions: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 考勤状态
        attenceStatusOptions: [],
        //考勤处理状态
        processStatusOptions:[],
        deviceOptions:[],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          checkDate: undefined
        },
        // 表单参数
        form: {},
        dialogVisible: false,
        open4: false,
        form1: {},
        open5: false,
      };
    },
    created() {
      this.getList();
      this.getDicts("attence_status").then(response => {
        this.attenceStatusOptions = response.data;
      });
      this.getDicts("device_access_type").then(response => {
        console.log(response.data);
        this.deviceOptions = response.data;
      });
      this.getDicts("leave_type").then(response => {
        this.leaveTypeOptions = response.data;
      });
      this.getDicts("leave_status").then(response => {
        this.leaveStatusOptions = response.data;
      });
      this.getDicts("absence_process_status").then(response => {
        this.processStatusOptions = response.data;
      });
    },
    methods: {
      //回填考勤状态
      attencestatusFormat(row, column) {
        return this.selectDictLabel(this.attenceStatusOptions, row.attenceStatus);
      },
      //回填考勤类型
      devicestatusFormat(row, column) {
        return this.selectDictLabel(this.deviceOptions, 2);
      },
      leaveTypeFormat(row, column) {
        return this.selectDictLabel(this.leaveTypeOptions, row.leaveType);
      },
      leaveStatusFormat(row, column) {
        return this.selectDictLabel(this.leaveStatusOptions, row.status);
      },
      // 字典设备状态字典翻译
      processStatusFormat(row, column) {
        return this.selectDictLabel(this.processStatusOptions, row.absenceProcessStatus);
      },
      /** 查询考勤记录列表 */
      getList() {
        this.loading = true;
        listsdattence(this.queryParams).then(response => {
            this.sdattenceList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      /*studentNameFormat(row,column){
       getBStudentByNo(row.studentNo).then(response=>{
         this.studentName= response.data.studentName;
       })
        return this.studentName;
      },*/
      storeyFormat(row, column) {
        return this.selectDictLabel(this.storeyOptions, row.storey);
      },
      bdormitoryFormat(row, column) {
        return this.selectDictLabel(this.bdormitoryOptions, row.bdormitoryId);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除考勤信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSdattence(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      // /** 导出按钮操作 */
      // handleExport() {
      //   const queryParams = this.queryParams;
      //   this.$confirm('是否确认导出所有卫生信息数据项?', "警告", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   }).then(function() {
      //     return exportSdHygiene(queryParams);
      //   }).then(response => {
      //     this.download(response.msg);
      //   }).catch(function() {});
      // },

      /** 请假详情按钮操作 */
      handleView4(row) {
        //this.open4 = true;
        const studentNo = row.studentNo;
        const leaveDate = row.accessDate;
        let params = {
                  studentNo: studentNo,
                  leaveDate: leaveDate,
                }
        queryleave(params).then(response => {
          this.form = response.data;
          this.open4 = true;
          this.title = "请假详情";
        });
      },
      /** 考勤异常详情按钮操作 */
      handleView5(row) {
        //this.open4 = true;
        const studentNo = row.studentNo;
        const createTime = row.accessDate;
        let params = {
                  studentNo: studentNo,
                  createTime: createTime,
                }
        queryexception(params).then(response => {
          if(response.data==null){
            alert("宿管老师未处理此数据!!!");
          }else{
            this.form1 = response.data;
            this.open5 = true;
            this.title = "考勤异常详情";
          }
        });
      }
    },

  };
</script>
